'''
User的服务类:核心操作，统一操作
'''
import  hashlib, base64,random,string

class UserService():

    #登录态Cookie的随机校验码
    @staticmethod
    def geneAuthCode(user_info):
        m = hashlib.md5()
        str = "%s-%s-%s-%s" % (user_info.uid, user_info.login_name,user_info.login_pwd,user_info.login_salt)
        m.update(str.encode("utf-8"))
        return m.hexdigest()

    # 用户登录密码的随机校验加密
    @staticmethod
    def genePwd (pwd, salt):
        m = hashlib.md5()
        str = "%s-%s"%(base64.encodebytes(pwd.encode('utf-8')) ,salt)
        m.update(str.encode("utf-8"))
        return  m.hexdigest()

    # 产生随机校验码salt
    @staticmethod
    def geneSalt(length=16):
        keylist = [random.choice((string.ascii_letters + string.digits)) for i in range(length)]
        return ("".join(keylist))